package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/setcookie")
public class SetCookieServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //创建cookie
        Cookie cookie1 = new Cookie("userName", "zhangsan");
        Cookie cookie2 = new Cookie("password", "123456");

        //将cookie传递给浏览器————通过resp
        resp.addCookie(cookie1);
        resp.addCookie(cookie2);

    }
}
